package com.qyy.www_chatroom.mapper;


import com.qyy.www_chatroom.model.Friend;
import com.qyy.www_chatroom.model.MessageSession;
import com.qyy.www_chatroom.model.MessageSessionUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface MessageSessionMapper {
    //根据userId获取到该用户都在哪些会话存在。返回结果是一组sessionId
    List<Integer> getSessionIdByUserId(int userId);

    //2.根据sessionId 来查询这个会话都包含哪些用户(除去自己)
    List<Friend> getFriendsBySessionId(@Param("sessionId") int sessionId,@Param("selfUserId") int selfUserId);

    //3.新增一个会话记录。返回会话的id

    @Options(useGeneratedKeys = true,keyProperty = "sessionId")
    @Insert("insert into message_session(sessionId, lastTime) values (null,now())")
    int addMessageSession(MessageSession messageSession);

    @Insert("insert into message_session_user(sessionId, userId) values (#{sessionId},#{userId})")
    int addMessageSessionUser(MessageSessionUser messageSessionuser);

}
